//
//  ShowInfoBtnView.m
//  JinFuThree
//
//  Created by 毛韶谦 on 2018/9/13.
//  Copyright © 2018年 毛韶谦. All rights reserved.
//

#import "ShowInfoBtnView.h"

@interface ShowInfoBtnView ()

@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *infoLabel;

@end


@implementation ShowInfoBtnView



/**
 展示信息页面
 
 @param view 添加到View
 @param image 需要的图片
 @param title 提示信息
 @param infoStr 详情信息
 @param btn 实现点击事件的Btn
 */
+(void)ShowInfoView:(UIView *)view withImage:(UIImage *)image WithTitle:(NSString *)title WithInfo:(NSString *)infoStr WithBtn:(UIButton *)btn {
    
    ShowInfoBtnView *infoView = [[ShowInfoBtnView alloc] initWithFrame:view.bounds];
    infoView.backgroundColor = [UIColor whiteColor];
    infoView.imageView.image = image;
    infoView.titleLabel.text = title;
    infoView.infoLabel.text = infoStr;
    [infoView addSubview:btn];
    [view addSubview:infoView];
    
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.colors = @[(__bridge id)HexColor(0xD6C096).CGColor, (__bridge id)HexColor(0xBEA471).CGColor];
    gradientLayer.locations = @[@0, @1];
    gradientLayer.startPoint = CGPointMake(0, 1);
    gradientLayer.endPoint = CGPointMake(1, 1);
    gradientLayer.frame = CGRectMake(0, 0, ScreenWidthMao - 50, 44);
    gradientLayer.cornerRadius = 4;
    gradientLayer.masksToBounds = YES;
    [btn.layer addSublayer:gradientLayer];
    
    UILabel *label = [[UILabel alloc] init];
    label.font = [UIFont systemFontOfSize:15];
    label.textColor = [UIColor whiteColor];
    label.text = btn.titleLabel.text;
    [btn addSubview:label];
    
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(infoView.mas_left).offset(25);
        make.right.mas_equalTo(infoView.mas_right).offset(-25);
        make.top.mas_equalTo(infoView.infoLabel.mas_bottom).offset(30);
        make.height.mas_equalTo(44);
    }];
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        
        [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self);
            make.size.mas_equalTo(CGSizeMake(130, 160));
            make.top.mas_equalTo(self.mas_top).offset(100);
        }];
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self);
            make.left.mas_equalTo(self.mas_left).offset(20);
            make.top.mas_equalTo(self.imageView.mas_bottom).offset(8);
        }];
        [self.infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self);
            make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(8);
            make.left.mas_equalTo(self.mas_left).offset(20);
        }];
    }
    return self;
}


- (UIImageView *)imageView {
    
    if (!_imageView) {
        _imageView = [[UIImageView alloc] init];
        [_imageView setContentMode:UIViewContentModeScaleAspectFit];
        
        [self addSubview:_imageView];
    }
    return _imageView;
}
- (UILabel *)titleLabel {
    
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        [_titleLabel setTextAlignment:NSTextAlignmentCenter];
        _titleLabel.font = [UIFont boldSystemFontOfSize:16];
        _titleLabel.textColor = HexColor(0x333333);
        
        [self addSubview:_titleLabel];
    }
    return _titleLabel;
}
- (UILabel *)infoLabel {
    
    if (!_infoLabel) {
        _infoLabel = [[UILabel alloc] init];
        [_infoLabel setTextAlignment:NSTextAlignmentCenter];
        _infoLabel.font = [UIFont systemFontOfSize:14];
        _infoLabel.textColor = HexColor(0x666666);
        _infoLabel.numberOfLines = 0;
        
        [self addSubview:_infoLabel];
    }
    return _infoLabel;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
